**************************************************
* This program performs the main empirical tests *
* on inventor mobility                           *
* reported in Table 3 Panel B & robustness tests *
**************************************************

	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	*Convert strings to numerics
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	*Set timeframe 
	drop if pyear < 1996 
	drop if pyear > 2018 
		

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}

	
	local pat "patcountpyear patcountpyear_adj patcitespyear patcitespyear_countclassadj patcitespyear_fyearadj  patcitespyear_fclassadj  patcitespyear_fyearadjt  patcitespyear_fclassadjt  generality originality originality_alt   " 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	

	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)

	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for year in which law was passed
	local DE_cow = 2001
	local OK_cow = 2002
	local MO_cow = 2004
	local KS_cow = 2005
	local TX_cow = 2006
	local NV_cow = 2008
	local NJ_cow = 2011
	local MD_cow = 2015
	local WA_cow = 2016

	*Initiate statelist macro
	local statelist "DE OK MO KS TX NV NJ MD WA"

	*cow: indicator equal to one if firm is incorporated in a state that has passed a corporate opportunities law
	gen cow = 0
	foreach state of local statelist {
			replace cow = 1 if incorp == "`state'" & pyear >= ``state'_cow'
	}

	
*********************************
* Table 3 Panel A Summary stats *
*********************************

		distinct inventor_id
		distinct permno 
		
		estpost tabstat cow move move_tostup superstarmove superstartostup patcountpyear patcitespyear generality originality, statistics (n mean sd p25 p50 p75) columns(statistics)
		
		

*******************************
* Table 3 Panel B Regressions *
*******************************

		reghdfe move cow  , absorb(inventor_id pyear#patgroupFE) vce(cluster permno)
		
		reghdfe move_tostup cow, absorb(inventor_id pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cow  , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		
		reghdfe superstartostup cow  , absorb(inventor_id pyear#patclassFE) vce(cluster permno) 

		

		
		
		
		
		
*======================================*
*           ROBUSTNESS TESTS	       *
*======================================*

		* noncompete index		
		gen nceindex=0
		replace nceindex=5 if incorp=="AL"
		replace nceindex=3 if incorp=="AK"
		replace nceindex=3 if incorp=="AZ"
		replace nceindex=5 if incorp=="AR"
		replace nceindex=0 if incorp=="CA"
		replace nceindex=1 if incorp=="CO"
		replace nceindex=2 if incorp=="CO" & pyear>=1992 
		replace nceindex=3 if incorp=="CO" & pyear>=2012 
		replace nceindex=4 if incorp=="CT"
		replace nceindex=3 if incorp=="CT" & pyear>=1992
		replace nceindex=6 if incorp=="DE"
		replace nceindex=7 if incorp=="DC"
		replace nceindex=7 if incorp=="FL"
		replace nceindex=9 if incorp=="FL" & pyear>=1997
		replace nceindex=5 if incorp=="GA"
		replace nceindex=6 if incorp=="GA" & pyear>=2005
		replace nceindex=7 if incorp=="GA" & pyear>=2011
		replace nceindex=3 if incorp=="HI"
		replace nceindex=4 if incorp=="HI" & pyear>=2007
		replace nceindex=5 if incorp=="ID"
		replace nceindex=6 if incorp=="ID" & pyear>=1992
		replace nceindex=7 if incorp=="ID" & pyear>=2009
		replace nceindex=5 if incorp=="IL"
		replace nceindex=6 if incorp=="IL" & (2012<=pyear<=2013) 
		replace nceindex=5 if incorp=="IN"
		replace nceindex=6 if incorp=="IA"
		replace nceindex=6 if incorp=="KS"
		replace nceindex=7 if incorp=="KS" & pyear>=2008
		replace nceindex=6 if incorp=="KY"
		replace nceindex=5 if incorp=="KY" & pyear>=2015
		replace nceindex=2 if incorp=="LA" & pyear<=1991
		replace nceindex=4 if incorp=="LA" & (1992<=pyear<=2001)
		replace nceindex=4 if incorp=="LA" & (2004<=pyear)
		replace nceindex=4 if incorp=="ME"
		replace nceindex=5 if incorp=="MD"
		replace nceindex=6 if incorp=="MA"
		replace nceindex=5 if incorp=="MI"
		replace nceindex=5 if incorp=="MN"
		replace nceindex=4 if incorp=="MS"
		replace nceindex=5 if incorp=="MS" & pyear>=2009
		replace nceindex=7 if incorp=="MO"
		replace nceindex=2 if incorp=="MT"
		replace nceindex=4 if incorp=="NE"
		replace nceindex=5 if incorp=="NV"
		replace nceindex=2 if incorp=="NH"
		replace nceindex=1 if incorp=="NH" & pyear>=2013
		replace nceindex=4 if incorp=="NJ"
		replace nceindex=2 if incorp=="NM"
		replace nceindex=3 if incorp=="NY"
		replace nceindex=4 if incorp=="NC"
		replace nceindex=0 if incorp=="ND"
		replace nceindex=4 if incorp=="OH"
		replace nceindex=5 if incorp=="OH" & pyear>=1992
		replace nceindex=6 if incorp=="OH" & pyear>=2005
		replace nceindex=1 if incorp=="OK"
		replace nceindex=6 if incorp=="OR"
		replace nceindex=5 if incorp=="OR" & pyear>=2008
		replace nceindex=6 if incorp=="PA"
		replace nceindex=3 if incorp=="RI"
		replace nceindex=5 if incorp=="SC"
		replace nceindex=4 if incorp=="SC" & pyear>=2011
		replace nceindex=5 if incorp=="SD"
		replace nceindex=7 if incorp=="TN"
		replace nceindex=5 if incorp=="TX"
		replace nceindex=3 if incorp=="TX" & pyear>=1995
		replace nceindex=4 if incorp=="TX" & pyear>=2011
		replace nceindex=6 if incorp=="UT"
		replace nceindex=5 if incorp=="VT"
		replace nceindex=6 if incorp=="VT" & pyear>=2006
		replace nceindex=4 if incorp=="VA" & (1980<=pyear<=1991)
		replace nceindex=3 if incorp=="VA" & (1992<=pyear<=2005)
		replace nceindex=4 if incorp=="VA" & (2006<=pyear<=2013)
		replace nceindex=5 if incorp=="VA" & (2014<=pyear)
		replace nceindex=5 if incorp=="WA"
		replace nceindex=2 if incorp=="WV" 
		replace nceindex=3 if incorp=="WV" & (1984<=pyear<=1991)
		replace nceindex=3 if incorp=="WI"
		replace nceindex=4 if incorp=="WI" & pyear>=2010
		replace nceindex=5 if incorp=="WI" & pyear>=2016
		replace nceindex=4 if incorp=="WY"

		* universal demand law
		gen ud=0
		replace ud=1 if incorp=="UT" & pyear>=1992
		replace ud=1 if incorp=="NH" & pyear>=1993
		replace ud=1 if incorp=="MS" & pyear>=1993
		replace ud=1 if incorp=="NC" & pyear>=1995
		replace ud=1 if incorp=="AZ" & pyear>=1996
		replace ud=1 if incorp=="NE" & pyear>=1996
		replace ud=1 if incorp=="CT" & pyear>=1997
		replace ud=1 if incorp=="ME" & pyear>=1997
		replace ud=1 if incorp=="PA" & pyear>=1997
		replace ud=1 if incorp=="TX" & pyear>=1997
		replace ud=1 if incorp=="WY" & pyear>=1997
		replace ud=1 if incorp=="ID" & pyear>=1998
		replace ud=1 if incorp=="HI" & pyear>=2001
		replace ud=1 if incorp=="IA" & pyear>=2003
		replace ud=1 if incorp=="MA" & pyear>=2004
		replace ud=1 if incorp=="RI" & pyear>=2005
		replace ud=1 if incorp=="SD" & pyear>=2005
		
		* The five most common types of antitakeover laws adopted by states since 1982. The law types are: control share acquisition laws (CS), business combination laws (BC), fair price laws (FP), directors' duties laws (DD), and poison pill laws (PP)
 
		* cs law
		gen cs=0
		replace cs =1 if incorp=="AZ" & pyear>=1987
		replace cs =1 if incorp=="FL" & pyear>=1987
		replace cs =1 if incorp=="HI" & pyear>=1985
		replace cs =1 if incorp=="ID" & pyear>=1988
		replace cs =1 if incorp=="IN" & pyear>=1986
		replace cs =1 if incorp=="KS" & pyear>=1988
		replace cs =1 if incorp=="LA" & pyear>=1987
		replace cs =1 if incorp=="MD" & pyear>=1989
		replace cs =1 if incorp=="MA" & pyear>=1987
		replace cs =1 if incorp=="MI" & pyear>=1988
		replace cs =1 if incorp=="MN" & pyear>=1984
		replace cs =1 if incorp=="MS" & pyear>=1990
		replace cs =1 if incorp=="MO" & pyear>=1984
		replace cs =1 if incorp=="NE" & pyear>=1988
		replace cs =1 if incorp=="NV" & pyear>=1987
		replace cs =1 if incorp=="NC" & pyear>=1987
		replace cs =1 if incorp=="OH" & pyear>=1982
		replace cs =1 if incorp=="OK" & pyear>=1987
		replace cs =1 if incorp=="OR" & pyear>=1987
		replace cs =1 if incorp=="PA" & pyear>=1990
		replace cs =1 if incorp=="SC" & pyear>=1988
		replace cs =1 if incorp=="SD" & pyear>=1990
		replace cs =1 if incorp=="TN" & pyear>=1988
		replace cs =1 if incorp=="UT" & pyear>=1987
		replace cs =1 if incorp=="VA" & pyear>=1989
		replace cs =1 if incorp=="WI" & pyear>=1984
		replace cs =1 if incorp=="WY" & pyear>=1990

		* bc law
		gen bc=0
		replace bc =1 if incorp=="AZ" & pyear>=1987
		replace bc =1 if incorp=="CT" & pyear>=1988
		replace bc =1 if incorp=="DE" & pyear>=1988
		replace bc =1 if incorp=="GA" & pyear>=1988
		replace bc =1 if incorp=="ID" & pyear>=1988
		replace bc =1 if incorp=="IL" & pyear>=1989
		replace bc =1 if incorp=="IN" & pyear>=1986
		replace bc =1 if incorp=="IA" & pyear>=1997
		replace bc =1 if incorp=="KS" & pyear>=1989
		replace bc =1 if incorp=="KY" & pyear>=1986
		replace bc =1 if incorp=="ME" & pyear>=1988
		replace bc =1 if incorp=="MD" & pyear>=1989
		replace bc =1 if incorp=="MA" & pyear>=1989
		replace bc =1 if incorp=="MI" & pyear>=1989
		replace bc =1 if incorp=="MN" & pyear>=1987
		replace bc =1 if incorp=="MO" & pyear>=1986
		replace bc =1 if incorp=="NE" & pyear>=1988
		replace bc =1 if incorp=="NV" & pyear>=1991
		replace bc =1 if incorp=="NJ" & pyear>=1986
		replace bc =1 if incorp=="NY" & pyear>=1985
		replace bc =1 if incorp=="OH" & pyear>=1990
		replace bc =1 if incorp=="OK" & pyear>=1991
		replace bc =1 if incorp=="OR" & pyear>=1991
		replace bc =1 if incorp=="PA" & pyear>=1988
		replace bc =1 if incorp=="RI" & pyear>=1990
		replace bc =1 if incorp=="SC" & pyear>=1988
		replace bc =1 if incorp=="SD" & pyear>=1990
		replace bc =1 if incorp=="TN" & pyear>=1988
		replace bc =1 if incorp=="TX" & pyear>=1997
		replace bc =1 if incorp=="VA" & pyear>=1988
		replace bc =1 if incorp=="WA" & pyear>=1987
		replace bc =1 if incorp=="WI" & pyear>=1987
		replace bc =1 if incorp=="WY" & pyear>=1989

		* fp law
		gen fp=0
		replace fp =1 if incorp=="AZ" & pyear>=1987
		replace fp =1 if incorp=="CT" & pyear>=1984
		replace fp =1 if incorp=="FL" & pyear>=1987
		replace fp =1 if incorp=="GA" & pyear>=1985
		replace fp =1 if incorp=="ID" & pyear>=1988
		replace fp =1 if incorp=="IL" & pyear>=1985
		replace fp =1 if incorp=="IN" & pyear>=1986
		replace fp =1 if incorp=="KY" & pyear>=1984
		replace fp =1 if incorp=="LA" & pyear>=1984
		replace fp =1 if incorp=="MD" & pyear>=1983
		replace fp =1 if incorp=="MI" & pyear>=1984
		replace fp =1 if incorp=="MN" & pyear>=1991
		replace fp =1 if incorp=="MS" & pyear>=1985
		replace fp =1 if incorp=="MO" & pyear>=1986
		replace fp =1 if incorp=="NV" & pyear>=1991
		replace fp =1 if incorp=="NJ" & pyear>=1986
		replace fp =1 if incorp=="NY" & pyear>=1985
		replace fp =1 if incorp=="NC" & pyear>=1987
		replace fp =1 if incorp=="OH" & pyear>=1990
		replace fp =1 if incorp=="PA" & pyear>=1988
		replace fp =1 if incorp=="RI" & pyear>=1990
		replace fp =1 if incorp=="SC" & pyear>=1988
		replace fp =1 if incorp=="SD" & pyear>=1990
		replace fp =1 if incorp=="TN" & pyear>=1988
		replace fp =1 if incorp=="VA" & pyear>=1985
		replace fp =1 if incorp=="WA" & pyear>=1985
		replace fp =1 if incorp=="WI" & pyear>=1984

		* dd law
		gen dd=0
		replace dd =1 if incorp=="AZ" & pyear>=1987
		replace dd =1 if incorp=="CT" & pyear>=1988
		replace dd =1 if incorp=="FL" & pyear>=1989
		replace dd =1 if incorp=="GA" & pyear>=1989
		replace dd =1 if incorp=="HI" & pyear>=1989
		replace dd =1 if incorp=="ID" & pyear>=1988
		replace dd =1 if incorp=="IL" & pyear>=1985
		replace dd =1 if incorp=="IN" & pyear>=1986
		replace dd =1 if incorp=="IA" & pyear>=1989
		replace dd =1 if incorp=="KY" & pyear>=1988
		replace dd =1 if incorp=="LA" & pyear>=1988
		replace dd =1 if incorp=="ME" & pyear>=1985
		replace dd =1 if incorp=="MD" & pyear>=1999
		replace dd =1 if incorp=="MA" & pyear>=1989
		replace dd =1 if incorp=="MN" & pyear>=1987
		replace dd =1 if incorp=="MS" & pyear>=1990
		replace dd =1 if incorp=="MO" & pyear>=1986
		replace dd =1 if incorp=="NE" & pyear>=1988
		replace dd =1 if incorp=="NV" & pyear>=1991
		replace dd =1 if incorp=="NJ" & pyear>=1989
		replace dd =1 if incorp=="NM" & pyear>=1987
		replace dd =1 if incorp=="NY" & pyear>=1987
		replace dd =1 if incorp=="NC" & pyear>=1993
		replace dd =1 if incorp=="ND" & pyear>=1993
		replace dd =1 if incorp=="OH" & pyear>=1984
		replace dd =1 if incorp=="OR" & pyear>=1989
		replace dd =1 if incorp=="PA" & pyear>=1990
		replace dd =1 if incorp=="RI" & pyear>=1990
		replace dd =1 if incorp=="SD" & pyear>=1990
		replace dd =1 if incorp=="TN" & pyear>=1988
		replace dd =1 if incorp=="TX" & pyear>=2003
		replace dd =1 if incorp=="VT" & pyear>=1998
		replace dd =1 if incorp=="VA" & pyear>=1988
		replace dd =1 if incorp=="WI" & pyear>=1987
		replace dd =1 if incorp=="WY" & pyear>=1990

		* pp law
		gen pp=0
		replace pp =1 if incorp=="CO" & pyear>=1989
		replace pp =1 if incorp=="CT" & pyear>=2003
		replace pp =1 if incorp=="FL" & pyear>=1989
		replace pp =1 if incorp=="GA" & pyear>=1988
		replace pp =1 if incorp=="HI" & pyear>=1988
		replace pp =1 if incorp=="ID" & pyear>=1988
		replace pp =1 if incorp=="IL" & pyear>=1989
		replace pp =1 if incorp=="IN" & pyear>=1986
		replace pp =1 if incorp=="IA" & pyear>=1989
		replace pp =1 if incorp=="KY" & pyear>=1988
		replace pp =1 if incorp=="ME" & pyear>=2002
		replace pp =1 if incorp=="MD" & pyear>=1999
		replace pp =1 if incorp=="MA" & pyear>=1989
		replace pp =1 if incorp=="MI" & pyear>=2001
		replace pp =1 if incorp=="MN" & pyear>=1995
		replace pp =1 if incorp=="MS" & pyear>=2005
		replace pp =1 if incorp=="MO" & pyear>=1999
		replace pp =1 if incorp=="NV" & pyear>=1989
		replace pp =1 if incorp=="NJ" & pyear>=1989
		replace pp =1 if incorp=="NY" & pyear>=1988
		replace pp =1 if incorp=="NC" & pyear>=1989
		replace pp =1 if incorp=="OH" & pyear>=1986
		replace pp =1 if incorp=="OR" & pyear>=1989
		replace pp =1 if incorp=="PA" & pyear>=1988
		replace pp =1 if incorp=="RI" & pyear>=1990
		replace pp =1 if incorp=="SC" & pyear>=1998
		replace pp =1 if incorp=="SD" & pyear>=1990
		replace pp =1 if incorp=="TN" & pyear>=1989
		replace pp =1 if incorp=="TX" & pyear>=2003
		replace pp =1 if incorp=="UT" & pyear>=1989
		replace pp =1 if incorp=="VT" & pyear>=2008
		replace pp =1 if incorp=="VA" & pyear>=1990
		replace pp =1 if incorp=="WA" & pyear>=1998
		replace pp =1 if incorp=="WI" & pyear>=1987
		replace pp =1 if incorp=="WY" & pyear>=2009

		* Revlon case
		gen revlon=0
		replace revlon =1 if incorp=="CA" & pyear>=2002
		replace revlon =1 if incorp=="DE" & pyear>=1986
		replace revlon =1 if incorp=="IL" & pyear>=1988
		replace revlon =1 if incorp=="IN" & pyear>=1987
		replace revlon =-1 if incorp=="IN" & pyear>=2001
		replace revlon =1 if incorp=="KS" & pyear>=2003
		replace revlon =-1 if incorp=="MD" & pyear>=2004
		replace revlon =1 if incorp=="MD" & pyear>=2009
		replace revlon =1 if incorp=="MI" & pyear>=1986
		replace revlon =1 if incorp=="MN" & pyear>=1987
		replace revlon =1 if incorp=="MO" & pyear>=1999
		replace revlon =1 if incorp=="NV" & pyear>=1997
		replace revlon =-1 if incorp=="NV" & pyear>=1999
		replace revlon =1 if incorp=="NH" & pyear>=2001
		replace revlon =1 if incorp=="NY" & pyear>=1986
		replace revlon =-1 if incorp=="NY" & pyear>=1997
		replace revlon =-1 if incorp=="NC" & pyear>=2001
		replace revlon =-1 if incorp=="OH" & pyear>=1990
		replace revlon =-1 if incorp=="PA" & pyear>=1987
		replace revlon =-1 if incorp=="VA" & pyear>=1999
		replace revlon =-1 if incorp=="WI" & pyear>=1999
		
		* Unocal case
		gen unocal=0
		replace unocal =1 if incorp=="AR" & pyear>=1993
		replace unocal =1 if incorp=="CA" & pyear>=1989
		replace unocal =1 if incorp=="DE" & pyear>=1985
		replace unocal =1 if incorp=="CA" & pyear>=2002
		replace unocal =1 if incorp=="FL" & pyear>=1989
		replace unocal =1 if incorp=="IL" & pyear>=1988
		replace unocal =1 if incorp=="IN" & pyear>=1987
		replace unocal =-1 if incorp=="IN" & pyear>=2001
		replace unocal =1 if incorp=="KS" & pyear>=2003
		replace unocal =-1 if incorp=="MD" & pyear>=1988
		replace unocal =1 if incorp=="MD" & pyear>=2004
		replace unocal =-1 if incorp=="MA" & pyear>=2003
		replace unocal =1 if incorp=="MI" & pyear>=1986
		replace unocal =1 if incorp=="MN" & pyear>=1987
		replace unocal =1 if incorp=="MO" & pyear>=1999
		replace unocal =-1 if incorp=="NV" & pyear>=1985
		replace unocal =-1 if incorp=="NJ" & pyear>=1998
		replace unocal =-1 if incorp=="NY" & pyear>=1986
		replace unocal =-1 if incorp=="NC" & pyear>=2001
		replace unocal =-1 if incorp=="OH" & pyear>=1986
		replace unocal =-1 if incorp=="PA" & pyear>=1986
		replace unocal =1 if incorp=="TX" & pyear>=1989
		replace unocal =-1 if incorp=="VA" & pyear>=1995
		replace unocal =1 if incorp=="WI" & pyear>=1989

		* Blasius case
		gen blasius=0
		replace blasius =1 if incorp=="CT" & pyear>=2000
		replace blasius =1 if incorp=="DE" & pyear>=1988
		replace blasius =-1 if incorp=="GA" & pyear>=1997
		replace blasius =-1 if incorp=="IN" & pyear>=1993
		replace blasius =-1 if incorp=="IN" & pyear>=2001
		replace blasius =1 if incorp=="KS" & pyear>=2003
		replace blasius =-1 if incorp=="MD" & pyear>=1999
		replace blasius =1 if incorp=="MD" & pyear>=2005
		replace blasius =1 if incorp=="MA" & pyear>=1990
		replace blasius =1 if incorp=="MI" & pyear>=2003
		replace blasius =1 if incorp=="NV" & pyear>=1997
		replace blasius =-1 if incorp=="NV" & pyear>=1999
		replace blasius =-1 if incorp=="NJ" & pyear>=1998
		replace blasius =-1 if incorp=="NC" & pyear>=1984
		replace blasius =-1 if incorp=="OH" & pyear>=1986
		replace blasius =-1 if incorp=="PA" & pyear>=1990
		replace blasius =-1 if incorp=="VA" & pyear>=1986
		
		* Madaroty classified board law
		gen mcb=0
		replace mcb =1 if incorp=="IN" & pyear>=2009
		replace mcb =1 if incorp=="IA" & pyear>=2011
		replace mcb =-1 if incorp=="IA" & pyear>=2014
		replace mcb =1 if incorp=="MA" & pyear>=1990
		replace mcb =1 if incorp=="OK" & pyear>=2010
		replace mcb =-1 if incorp=="OK" & pyear>=2013
		

	
************************************	
* Table 10 HQ state = Incorp state *
************************************	

		reghdfe move cow if incorp==state , absorb(inventor_id pyear#patgroupFE) vce(robust)
		
		reghdfe move_tostup cow if incorp==state , absorb(inventor_id pyear patclassFE) vce(robust)
	
		reghdfe superstarmove cow  if incorp==state , absorb(inventor_id pyear patclassFE) vce(robust)
		
		reghdfe superstartostup cow  if incorp==state , absorb(inventor_id pyear patclassFE) vce(robust)

		
**************************	
* Table 11 Drop DE firms *
**************************	

		reghdfe move cow if state~="DE" , absorb(inventor_id pyear#patgroupFE) vce(cluster permno)
		
		reghdfe move_tostup cow if state~="DE", absorb(inventor_id pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cow if state~="DE"  , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		
		reghdfe superstartostup cow if state~="DE"  , absorb(inventor_id pyear#patclassFE) vce(cluster permno) 

		
**************************************	
* Table 13 Additional legal controls *
**************************************
			
		reghdfe move cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius , absorb(inventor_id pyear#patgroupFE) vce(robust)
		
		reghdfe move_tostup cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius, absorb(inventor_id pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		
		reghdfe superstartostup cow nceindex ud mcb cs bc fp dd pp revlon unocal blasius , absorb(inventor_id pyear#patclassFE) vce(cluster permno) 

		
*******************************************	
* Table 14 High dimensional fixed effects *
*******************************************	

		reghdfe move cow  , absorb(inventor_id lstateFE#pyear#patgroupFE) vce(cluster permno)
		
		reghdfe move_tostup cow, absorb(inventor_id lstateFE#pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cow  , absorb(inventor_id lstateFE#pyear#patclassFE) vce(cluster permno)
		
		reghdfe superstartostup cow  , absorb(inventor_id lstateFE#pyear#patclassFE) vce(cluster permno) 

		
************************	
* Table 15 Matched DiD *
************************
		
		psmatch2 treatment i.lstateFE i.pyear i.patgroupFE, n(1)		
		bys permno: egen matching_sample = sum(_weight)
		
	
		reghdfe move cow if matching_sample!=0 , absorb(inventor_id lstateFE#pyear#patgroupFE) 
		
		reghdfe move_tostup cow if matching_sample!=0, absorb(inventor_id lstateFE#pyear#patgroupFE) 
	
		reghdfe superstarmove cow if matching_sample!=0 , absorb(inventor_id lstateFE#pyear#patgroupFE) 
		
		reghdfe superstartostup cow if matching_sample!=0 , absorb(inventor_id lstateFE#pyear#patgroupFE) 
		
		
************************		
* Table 16 Stacked DiD *
************************		

		expand 2, gen(event_DE)
		drop if event_DE==1 & treatment==1 & incorp~="DE" 
		drop if event_DE==1 & (pyear<1996 | pyear>2004)

		expand 2 if event_DE==0, gen(event_OK)
		drop if event_OK==1 & treatment==1 & incorp~="OK"
		drop if event_OK==1 & (pyear<1997 | pyear>2005)

		expand 2 if event_DE==0 & event_OK==0, gen(event_MO)
		drop if event_MO==1 & treatment==1 & incorp~="MO"
		drop if event_MO==1 & (pyear<1999 | pyear>2007)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0, gen(event_KS)
		drop if event_KS==1 & treatment==1 & incorp~="KS"
		drop if event_KS==1 & (pyear<2001 | pyear>2009)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0, gen(event_TX)
		drop if event_TX==1 & treatment==1 & incorp~="TX"
		drop if event_TX==1 & (pyear<2002 | pyear>2010)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0, gen(event_NV)
		drop if event_NV==1 & treatment==1 & incorp~="NV"
		drop if event_NV==1 & (pyear<2003 | pyear>2011)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0, gen(event_NJ)
		drop if event_NJ==1 & treatment==1 & incorp~="NJ"
		drop if event_NJ==1 & (pyear<2007 | pyear>2015)
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0, gen(event_MD)
		drop if event_MD==1 & treatment==1 & incorp~="MD"
		drop if event_MD==1 & (pyear<2010 | pyear>2018) 
		
		expand 2 if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0, gen(event_WA)
		drop if event_WA==1 & treatment==1 & incorp~="WA"
		drop if event_WA==1 & (pyear<2012 | pyear>2020)
		
		drop if event_DE==0 & event_OK==0 & event_MO==0 & event_KS==0 & event_TX==0 & event_NV==0 & event_NJ==0 & event_MD==0 & event_WA==0
	
		reghdfe move cow  , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		
		reghdfe move_tostup cow, absorb(inventor_id pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cow  , absorb(inventor_id pyear#patgroupFE) vce(cluster permno)
		
		reghdfe superstartostup cow  , absorb(inventor_id pyear#patclassFE) vce(cluster permno) 

		
		
********************************
* Table B3 Dynamic coeff trend *
********************************

	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	*Convert strings to numerics
	encode state, gen(lstateFE)
	encode incorp, gen(istateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	*Set timeframe 
	drop if pyear < 1996 
	drop if pyear > 2018 
		

	*Drop if missing headquarter state
	drop if missing(state)
	*Drop if missing state of incorporation
	drop if missing(incorp)
	*Drop if not incorporated in U.S. state
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}

	
	local pat "patcountpyear patcountpyear_adj patcitespyear patcitespyear_countclassadj patcitespyear_fyearadj  patcitespyear_fclassadj  patcitespyear_fyearadjt  patcitespyear_fclassadjt  generality originality originality_alt   " 
	foreach v of local pat {
		replace `v'=0 if missing(`v')
		gen ln_`v' = log(1+`v')
	}
	

	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)

	

	local statelist "DE OK MO KS TX NV NJ MD WA"
	gen treatment = 0
	foreach state of local statelist {
			replace treatment = 1 if incorp == "`state'"
	}

	*Create macros for year in which law was passed
	local DE_cow = 2001
	local OK_cow = 2002
	local MO_cow = 2004
	local KS_cow = 2005
	local TX_cow = 2006
	local NV_cow = 2008
	local NJ_cow = 2011
	local MD_cow = 2015
	local WA_cow = 2016

	*Initiate statelist macro
	local statelist "DE OK MO KS TX NV NJ MD WA"

	*cow: indicator equal to one if firm is incorporated in a state that has passed a corporate opportunities law
	gen cow = 0
	foreach state of local statelist {
			replace cow = 1 if incorp == "`state'" & pyear >= ``state'_cow'
	}

	
	*Initialize variables
		forval x=1/25 {
			gen cown`x'=0
			}

		forval x=0/25 {
			gen cow`x'=0
			}


		gen cow2p = 0
		gen cow3p = 0
		gen cow4p = 0

		*Generate event time index
		gen indexyear=0
		local DE_cow = 2001
		local OK_cow = 2002
		local MO_cow = 2004
		local KS_cow = 2005
		local TX_cow = 2006
		local NV_cow = 2008
		local NJ_cow = 2011
		local MD_cow = 2015
		local WA_cow = 2016
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
			forval x=-25(1)25 {
			replace indexyear=`x' if incorp == "`state'" & pyear == ``state'_cow'+`x'
			}
			}	
		
		*Generate event time dummies
		local DE_cow = 2001
		local OK_cow = 2002
		local MO_cow = 2004
		local KS_cow = 2005
		local TX_cow = 2006
		local NV_cow = 2008
		local NJ_cow = 2011
		local MD_cow = 2015
		local WA_cow = 2016
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
			forval x=1/25 {
			replace cown`x' = 1 if incorp == "`state'" & pyear == ``state'_cow'-`x'
			}
			}	
			
		local DE_cow = 2001
		local OK_cow = 2002
		local MO_cow = 2004
		local KS_cow = 2005
		local TX_cow = 2006
		local NV_cow = 2008
		local NJ_cow = 2011
		local MD_cow = 2015
		local WA_cow = 2016
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
			forval x=0/25 {
			replace cow`x' = 1 if incorp == "`state'" & pyear == ``state'_cow'+`x'
			}
			}
			
		local DE_cow = 2001
		local OK_cow = 2002
		local MO_cow = 2004
		local KS_cow = 2005
		local TX_cow = 2006
		local NV_cow = 2008
		local NJ_cow = 2011
		local MD_cow = 2015
		local WA_cow = 2016
		local statelist "DE OK MO KS TX NV NJ MD WA"
		foreach state of local statelist {
			replace cow2p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+2
			replace cow3p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+3
			replace cow4p = 1 if incorp == "`state'" & pyear >= ``state'_cow'+4
			}

		
		reghdfe move cown2 cown1 cow0 cow1 cow2 cow3p  , absorb(inventor_id pyear#patgroupFE) vce(cluster permno)
		
		reghdfe move_tostup cown2 cown1 cow0 cow1 cow2 cow3p, absorb(inventor_id pyear#patclassFE) vce(cluster permno)
	
		reghdfe superstarmove cown2 cown1 cow0 cow1 cow2 cow3p  , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		
		reghdfe superstartostup cown2 cown1 cow0 cow1 cow2 cow3p  , absorb(inventor_id pyear#patclassFE) vce(cluster permno) 
	
		
		
*******************************
* Figure B2 Block permutation *
*******************************
	
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}
	

	
	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)


	* Loop 1000;

		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe move cow_`y' , absorb(inventor_id pyear#patgroupFE) vce(cluster permno)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "move_loop1.csv", cells(b) replace
		
		
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}
	

	
	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)


	* Loop 1000;

		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe move_tostup cow_`y' , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "move_tostup_loop1.csv", cells(b) replace
		
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}
	

	
	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)


	* Loop 1000;

		forval y= 1/250 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe superstarmove cow_`y' , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "superstarmove_loop1.csv", cells(b) replace
		
		
	clear all
	global path "C:\cow"
	global out "$path\out"
	use "$path\inventorlevel.dta"
	set more off

	encode state, gen(lstateFE)
	encode patgroup, gen(patgroupFE)
	encode class, gen(patclassFE)

	drop if pyear < 1996 
	drop if pyear > 2018 
		
	drop if missing(state)
	drop if missing(incorp)
	drop if inlist(incorp, "AS", "INTL", "PR", "TT", "VI")

	*Generate variables
	local inno "move move_topriv move_pubtopriv move_tostup move_pubtostup"
	foreach v of local inno {
		replace `v'=0 if missing(`v')
	}
	

	
	gen superstar=0
	replace superstar=1 if cites_raw>=90

	gen superstartostup=0
	replace superstartostup=1 if move_tostup==1 & superstar==1
		
	gen superstarmove=0
	replace superstarmove=1 if (superstar==1 & move==1)


	* Loop 1000;

		forval y= 1/1000 {
		bysort permno: gen ryear_`y' = runiformint(1996,2018)
		bysort permno: replace ryear_`y' = ryear_`y'[1]
		bysort permno: gen treatment_`y' = runiformint(0,1)
		bysort permno: replace treatment_`y' = treatment_`y'[1]
		gen cow_`y' =0
		replace cow_`y' =1 if treatment_`y'==1 & pyear >= ryear_`y'
	
		quietly reghdfe superstartostup cow_`y' , absorb(inventor_id pyear#patclassFE) vce(cluster permno)
		estimate store m`y'
		drop ryear_`y' treatment_`y' cow_`y'   
		}

		estout m* using "superstartostup_loop1.csv", cells(b) replace
		
